/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.star.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.star.modules.sys.entity.ShPic;
import com.star.modules.sys.service.ShPicService;

/**
 * 图片管理Controller
 * @author L
 * @version 2018-09-03
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/shPic")
public class ShPicController extends BaseController {

	@Autowired
	private ShPicService shPicService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ShPic get(String id, boolean isNewRecord) {
		return shPicService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sys:shPic:view")
	@RequestMapping(value = {"list", ""})
	public String list(ShPic shPic, Model model) {
		model.addAttribute("shPic", shPic);
		return "modules/sys/shPicList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sys:shPic:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ShPic> listData(ShPic shPic, HttpServletRequest request, HttpServletResponse response) {
		Page<ShPic> page = shPicService.findPage(new Page<ShPic>(request, response), shPic); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sys:shPic:view")
	@RequestMapping(value = "form")
	public String form(ShPic shPic, Model model) {
		model.addAttribute("shPic", shPic);
		return "modules/sys/shPicForm";
	}

	/**
	 * 保存图片管理
	 */
	@RequiresPermissions("sys:shPic:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ShPic shPic) {
		shPicService.save(shPic);
		return renderResult(Global.TRUE, "保存图片管理成功！");
	}
	
	/**
	 * 停用图片管理
	 */
	@RequiresPermissions("sys:shPic:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(ShPic shPic) {
		shPic.setStatus(ShPic.STATUS_DISABLE);
		shPicService.updateStatus(shPic);
		return renderResult(Global.TRUE, "停用图片管理成功");
	}
	
	/**
	 * 启用图片管理
	 */
	@RequiresPermissions("sys:shPic:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(ShPic shPic) {
		shPic.setStatus(ShPic.STATUS_NORMAL);
		shPicService.updateStatus(shPic);
		return renderResult(Global.TRUE, "启用图片管理成功");
	}
	
	/**
	 * 删除图片管理
	 */
	@RequiresPermissions("sys:shPic:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ShPic shPic) {
		shPicService.delete(shPic);
		return renderResult(Global.TRUE, "删除图片管理成功！");
	}
	
}